<include file="../Public/header" />

	
	<link href="__PUBLIC__/themes/blue/layout.css" rel="stylesheet" type="text/css" />
</head>


<script type="text/javascript" src="__PUBLIC__/js/tbox/tbox.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/admin.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-admin-box.js"></script>

<!-- tbox用常量 -->
<script>
	var THEME = "__THEME__";
	var APP    = "__APP__";
	var URL    = "__URL__";
	var PUBLIC = "../Public";
	var SITE_URL = "{*SITE_URL}";
</script>

<body>
<div id="container_s">
	<!-- 添加新的积分策略 BEGIN -->
	<form action="{:U('admin/System/doAddSchedule')}" method="post">
		<table class="tableborder" width="100%" id="schedule">
			<tbody>
				<tr class="top">
					<td class="border" colspan="2"></td>
				</tr>
				<tr onclick="$('#schedule .cell').toggle();">
					<th class="header" colspan="2">新建计划任务</th>
				</tr>
				<tr class="label cell">
					<th>说明</th>
					<th>设置</th>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>简介</b><br/>
						<span class="smalltxt">对计划任务的简要描述</span>
					</td>
					<td class="altbg2"><input style="width:250px;" name="info" class="txt mr10" value="" /><span id="tip"></span></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>任务函数</b><br/>
						<span class="smalltxt">计划任务执行的函数，格式为：app/Model/method</span>
					</td>
					<td class="altbg2"><input name="task_to_run" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>计划任务类型</b>
						<br/>
						<span class="smalltxt">ONCE、MINUTE、HOURLY、DAILY、WEEKLY、MONTHLY 之一</span>
					</td>
					<td class="altbg2"><input name="schedule_type" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>计划频率</b><br/>
						<span class="smalltxt">类型为MONTHLY时必须；ONCE时无效；其他时为可选，默认为1。</span>
					</td>
					<td class="altbg2"><input name="modifier" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>dirlist</b><br/>
						<span class="smalltxt">指定周或月的一天或多天。只与WEEKLY和MONTHLY共同使用时有效，其他时忽略。</span>
					</td>
					<td class="altbg2"><input name="dirlist" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>month</b><br/>
						<span class="smalltxt">指定一年中的一个月或多个月.只在schedule_type=MONTHLY时有效，其他时忽略。<br/>当modifier=LASTDAY时必须，其他时可选。有效值：Jan ～ Dec，默认为*(每个月)</span>
					</td>
					<td class="altbg2"><input name="month" style="width:250px;" class="txt" value =""/></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>开始时间</b><br/>
						<span class="smalltxt">任务启动时间，使用“Y-m-d H:i:s”格式</span>
					</td>
					<td class="altbg2"><input name="start_datetime" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>失效时间</b><br/>
						<span class="smalltxt">失效时间，使用“Y-m-d H:i:s”格式</span>
					</td>
					<td class="altbg2"><input name="end_datetime" style="width:250px;" class="txt" value ="" /></td>
				</tr>
				<tr class="cell">
					<td class="footer" colspan="2">
						<input type="submit" class="button mt10 mb10"  value="提交" />
					</td>
				</tr>
			</tbody>
		</table>
	</form>
	<!-- 添加新的积分策略 END -->

	<!-- 所有计划任务 BEGIN -->
	<form method="post" id="form_all" name="form_all" action="{:U('admin/System/doSaveAllSchedule')}">
		<table class="tableborder" width="100%">
			<tbody>
				<tr class="top">
					<td class="border" colspan="11"></td>
				</tr>
				<tr>
					<th class="header" colspan="11">计划任务管理</th>
				</tr>
				<tr class="label">
					<th>ID</th>
					<th>任务</th>
					<th>任务简介</th>
					<th>任务类型</th>
					<th>计划频率</th>
					<th>dirlist</th>
					<th>month</th>
					<th>开始时间</th>
					<th>失效时间</th>
					<th>上次执行时间</th>
					<th>&nbsp;</th>
				</tr>
				<volist name="list" id="vo">
				<tr class="cell altbg1" id="list_{$vo['id']}">
					<td>
						<label><input type="checkbox" class="schedule_admin_check" rel="0" dataId="{$vo['id']}"></label> 
						{$vo['id']}
					</td>
					<td><input id="method_{$vo['id']}"	 type="text" class="large bLeftRequire" name="task_to_run[{$vo['id']}]"		style="width:150px;" value="{$vo['method']}" /></td>
					<td><input id="info_{$vo['id']}"	 type="text" class="large bLeftRequire" name="info[{$vo['id']}]"			style="width:80px;"  value="{$vo['info']}" /></td>
					<td><input id="type_{$vo['id']}"	 type="text" class="large bLeftRequire" name="schedule_type[{$vo['id']}]"	style="width:40px;"  value="{$vo['schedule_type']}" /></td>
					<td><input id="modifier_{$vo['id']}" type="text" class="large bLeftRequire" name="modifier[{$vo['id']}]"		style="width:40px;"  value="{$vo['modifier']}" /></td>
					<td><input id="dirlist_{$vo['id']}"  type="text" class="large bLeftRequire" name="dirlist[{$vo['id']}]"			style="width:40px;"  value="{$vo['dirlist']}" /></td>
					<td><input id="month_{$vo['id']}"	 type="text" class="large bLeftRequire" name="month[{$vo['id']}]"			style="width:40px;"  value="{$vo['month']}" /></td>
					<td><input id="start_{$vo['id']}"	 type="text" class="large bLeftRequire" name="start_datetime[{$vo['id']}]"	style="width:120px;" value="{$vo['start_datetime']}" /></td>
					<td><input id="end_{$vo['id']}"		 type="text" class="large bLeftRequire" name="end_datetime[{$vo['id']}]"	style="width:120px;" value="{$vo['end_datetime']}" /></td>
					<td><input id="last_{$vo['id']}"	 type="text" class="large bLeftRequire" name="last_run_time[{$vo['id']}]"	style="width:120px;" value="{$vo['last_run_time']}" /></td>
					<td><input type="button" onclick="edit_one({$vo['id']});" value="保存" class="button" />
				</tr>
				</volist>
				<tr>
					<td class="footer" colspan="11"> <input type="submit" value="保存全部" class="button mt10 mb10" /></td>
				</tr>
			</tbody>
		</table>
	</form>
	<!-- 所有计划任务 BEGIN -->
</div>

<!-- 前台管理 BEGIN -->
<div id="schedule_admin" style="display:none;">
	<a href="javascript:void(0)" onclick="deleteSchedule()">删除计划任务</a>
</div>
<!-- 前台管理 END -->

<!-- 页面JS BEGIN -->
<script type="text/javascript">
	//加载前台管理工具
	$(function(){
		$.fn.admin({
			prefix:'schedule_',
			checkClass:'schedule_admin_check',
			hiddenId:'schedule_admin',
			lMinOffset:1,
			type:false,
			position:'right'
		});
	});

	//编辑一条计划任务
	function edit_one(sid) {
		met = $('#method_'+sid).val();
		inf = $('#info_'+sid).val();
		typ = $('#type_'+sid).val();
		mod = $('#modifier_'+sid).val();
		dirl = $('#dirlist_'+sid).val();
		mon = $('#month_'+sid).val();
		sta = $('#start_'+sid).val();
		end = $('#end_'+sid).val();
		las = $('#last_'+sid).val();
		$.post("{:U('admin/System/doSaveOneSchedule')}", {id:sid, task_to_run:met, info:inf, schedule_type:typ, modifier:mod, dirlist:dirl, month:mon, start_datetime:sta, end_datetime:end, last_run_time:las}, function(result){
			if(result == 1) {
				$.tbox.yes('保存成功',"提示");
				setTimeout("$.tbox.close()",1500);
			}else{
				$.tbox.no('保存失败',"提示");
				setTimeout("$.tbox.close()",1500);
			}
		});
	}

	//删除
	function deleteSchedule() {
		if(confirm('确认要将所选附件删除至回收站吗？')){
			$.post("{:U('admin/System/doDeleteSchedule')}", {id:$.fn.getData('schedule_')}, function(result){
				if(result == 1) {
					$.tbox.yes('删除成功',"提示");
					setTimeout("$.tbox.close()",1500);
					$.each($.fn.getData('schedule_'),function(i,n){
						$("#list_"+n).remove();
					});
					$('#schedule_admin_box').hide();
				}else{
					$.tbox.no('删除失败',"提示");
					setTimeout("$.tbox.close()",1500);
				}
			});
		}
	}
</script>
<!-- 页面JS END -->

</body>
</html>
